#include <iostream>
#include <algorithm>

using namespace std;

void swap(char* a, char* b) {
    char tmp = *a;
    *a = *b;
    *b = tmp;
}

// Permutation of a string with unique characters
// f(123) = 1 + f(23) = 1 + 2 + f(3)  recursive!
void Permutation(char* pStr, char* pPos) {
    if (*pPos == '\0') {
        cout << pStr << endl;
    } else {
        for (char* pChar = pPos; *pChar != '\0'; pChar++) {
            swap(*pChar, *pPos);
            Permutation(pStr, pPos + 1);
            swap(*pChar, *pPos);
        }
    }
}

int main(void) {
    char test[] = "132";
    Permutation(test, test);
    Permutation(test, test);
    cout << endl;
    return 0;
}
